package com.arcaneshift.model.action.game;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.arcaneshift.model.util.TerranType;

public class Terran implements Serializable {
	private static final long serialVersionUID = 1L;
	
	private List<List<TerranType>> matrix;
	private String name;
	
	public Terran(int x, int y) {
		matrix = new ArrayList<List<TerranType>>();
		
		for (int i = 0; i < x; i++) {
			List<TerranType> terranLine = new ArrayList<TerranType>();
			
			for (int j = 0; j < y; j++) {
				terranLine.add(TerranType.GROUND);
			}
			
			matrix.add(terranLine);
		}
	}
	
	public List<List<TerranType>> getMatrix() {
		return matrix;
	}
	
	public TerranType get(int x, int y) {
		if (x < matrix.size()) {
			if (y < matrix.get(x).size()) {
				return matrix.get(x).get(y);
			}
		}
		
		return null;
	}
	
	/**
	 * Create a String matrix with the numbers of each terran square.
	 * 
	 * @return
	 */
	public String toLogicString() {
		StringBuilder builder = new StringBuilder();
		
		for (int i = 0; i < matrix.size(); i++) {
			for (int j = 0; j < matrix.get(i).size(); j++) {
				builder.append(matrix.get(i).get(j).getNumericValue());
				builder.append(' ');
			}
			builder.append('\n');
		}
		
		return builder.toString();
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
